%% Author: Dmitriid
%% Created: 20.09.2006
%% Description: TODO: Add desciption to orcas_soap_decoder
-module(orcas_soap_decoder).

%%
%% Include files
%%

-include_lib("xmerl/include/xmerl.hrl").

%%
%% Exported Functions
%%
-export([decode/1]).

%%
%% API Functions
%%

decode(Xml) ->
    {Doc, _} = xmerl_scan:string(Xml),
    Body = xmerl_xpath:string("/soap:Envelope/soap:Body/*", Doc),
    parse(xmerl_tools:remove_empty(Body)).

decode_file(File) ->
    {Doc, _} = xmerl_scan:file(File),
    Body = xmerl_xpath:string("/soap:Envelope/soap:Body/*", Doc),
    parse(xmerl_tools:remove_empty(Body)).
%%
%% Local Functions
%%

parse([H|L]) ->
    [parseElement(H)] ++ parse(L);
parse([]) ->
	[].

parseElement(#xmlElement{name = Name, content = Content}) ->
    {Name, parse(Content)};
parseElement(#xmlText{value = Val}) ->
    Val.